package com.example.demo;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Controller {
    //引入Redis模板(引入自己本身)
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/set")
    public String set(){
        //redis的写操作
        stringRedisTemplate.opsForValue().set("name","zhangsan");
        return "Redis存储成功";
    }

    @RequestMapping("/get")
    public String get(){
        //redis的写操作
        String res = stringRedisTemplate.opsForValue().get("name");
        return res;
    }

}
